package com.ruoyi.mongo.emtity;

import java.util.Date;
import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import com.alibaba.fastjson.JSONObject;

@Document(collection="test_user")  // 指定集合名称
public class User {
	/**
     * 	使用@Id注解指定MongoDB中的 _id 主键
     *  MongoDB中，默认的主键类型是ObjectId，对应Java中的类型是String|ObjectId(是Bson包中的。)
     */
    @Id
    private ObjectId id;
    private String name;
    private Integer age;
    private String sex;
    private Integer score;
    private JSONObject secrets;
    /**
     *	创建一个5秒之后文档自动删除的索引
     *  spring并不推荐在以此方式创建索引
     * 	需要设置 auto-index-creation: true  // 允许创建索引
     */
    //@Indexed(expireAfterSeconds=5)  
    /**
     *	用于配置Java实体属性和MongoDB集合Field字段的映射关系。
     *	默认映射关系是同名映射
     */
    @Field("create_time")
    private Date createTime;
    
    // 创建索引并指定过期时间
    //expireAfterSeconds直接设置时间，秒为单位。
    // 注意只能为时间类型的字段设置
    // db.test_user.createIndex( { "UpdateTime": 1 }, { expireAfterSeconds: 1 } )

    /**
     *	映射忽略的字段，该字段不会保存到mongodb，
     */
    @Transient
    private Date UpdateTime;
    private List<String> hobbys;
	public ObjectId getId() {
		return id;
	}
	public void setId(ObjectId id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public JSONObject getSecrets() {
		return secrets;
	}
	public void setSecrets(JSONObject secrets) {
		this.secrets = secrets;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public Date getUpdateTime() {
		return UpdateTime;
	}
	public void setUpdateTime(Date updateTime) {
		UpdateTime = updateTime;
	}
	public List<String> getHobbys() {
		return hobbys;
	}
	public void setHobbys(List<String> hobbys) {
		this.hobbys = hobbys;
	}
	public Integer getScore() {
		return score;
	}
	public void setScore(Integer score) {
		this.score = score;
	}
	@Override
	public String toString() {
		return "User [id=" + id + ", name=" + name + ", age=" + age + ", sex=" + sex + ", score=" + score + ", secrets="
				+ secrets + ", createTime=" + createTime + ", UpdateTime=" + UpdateTime + ", hobbys=" + hobbys + "]";
	}
	

}
